/*
 * @Author: Await
 * @Date: 2025-05-10 16:00:00
 * @LastEditors: Await
 * @LastEditTime: 2025-05-10 16:00:00
 * @Description: 预设主题配置
 */

import { ThemeConfig } from '../../../../types/chartTypes';

// 导出预设主题名称数组 - 解决缺少presetThemeNames错误
export const presetThemeNames: Record<string, string> = {
  'default': '默认主题',
  'dark': '暗黑主题',
  'light': '明亮主题',
  'chalk': '粉笔风格',
  'essos': '伊索斯',
  'macarons': '马卡龙',
  'purple-passion': '紫色激情',
  'roma': '罗马',
  'shine': '光彩',
  'vintage': '复古',
  'walden': '瓦尔登',
  'westeros': '维斯特洛',
  'wonderland': '仙境'
};

// 导出预设主题对象 - 解决缺少presetThemes错误
export const presetThemes: Record<string, any> = {
  'default': { themeName: '默认主题', color: ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de'] },
  'dark': { themeName: '暗黑主题', backgroundColor: '#333', textStyle: { color: '#fff' } },
  'light': { themeName: '明亮主题', backgroundColor: '#fff', textStyle: { color: '#333' } }
};

// 导出预设主题预览图片路径 - 解决缺少presetThemePreviews错误
export const presetThemePreviews: Record<string, string> = {
  'default': './assets/images/themes/theme_default.jpg',
  'dark': './assets/images/themes/theme_dark.jpg',
  'light': './assets/images/themes/theme_light.jpg',
  'chalk': './assets/images/themes/theme_chalk.jpg',
  'essos': './assets/images/themes/theme_essos.jpg',
  'macarons': './assets/images/themes/theme_macarons.jpg',
  'purple-passion': './assets/images/themes/theme_purple-passion.jpg',
  'roma': './assets/images/themes/theme_roma.jpg',
  'shine': './assets/images/themes/theme_shine.jpg',
  'vintage': './assets/images/themes/theme_vintage.jpg',
  'walden': './assets/images/themes/theme_walden.jpg',
  'westeros': './assets/images/themes/theme_westeros.jpg',
  'wonderland': './assets/images/themes/theme_wonderland.jpg'
};

interface Preset {
  name: string;
  config: Partial<ThemeConfig>;
}

// 默认预设
export const defaultPresets: Preset[] = [
  {
    name: '经典图表',
    config: {
      line: {
        symbol: 'emptyCircle',
        symbolSize: 4,
        smooth: false,
        lineStyle: {
          width: 2,
          type: 'solid',
        },
      },
      bar: {
        barWidth: '40%',
        barGap: '30%',
        itemStyle: {
          barBorderWidth: 0,
          barBorderRadius: 0,
        },
      },
      pie: {
        borderWidth: 2,
        borderRadius: 0,
        label: {
          color: '#333',
        },
      },
    },
  },
  {
    name: '圆润风格',
    config: {
      line: {
        symbol: 'circle',
        symbolSize: 6,
        smooth: true,
        lineStyle: {
          width: 3,
          type: 'solid',
        },
      },
      bar: {
        barWidth: '50%',
        barGap: '20%',
        itemStyle: {
          barBorderWidth: 0,
          barBorderRadius: 5,
        },
      },
      pie: {
        borderWidth: 0,
        borderRadius: 8,
        label: {
          color: '#333',
        },
      },
    },
  },
  {
    name: '科技风格',
    config: {
      line: {
        symbol: 'rect',
        symbolSize: 5,
        smooth: false,
        lineStyle: {
          width: 2,
          type: 'dashed',
        },
      },
      bar: {
        barWidth: '30%',
        barGap: '40%',
        itemStyle: {
          barBorderWidth: 1,
          barBorderRadius: 0,
        },
      },
      pie: {
        borderWidth: 1,
        borderRadius: 0,
        label: {
          color: '#333',
        },
      },
    },
  }
];

// 获取本地存储的预设
export const loadUserPresets = (): Preset[] => {
  try {
    const savedPresets = localStorage.getItem('theme-presets');
    if (savedPresets) {
      return JSON.parse(savedPresets);
    }
  } catch (error) {
    console.error('加载用户预设失败:', error);
  }
  return [];
};

// 保存预设到本地存储
export const saveUserPreset = (preset: Preset): void => {
  try {
    const userPresets = loadUserPresets();
    const updatedPresets = [...userPresets, preset];
    localStorage.setItem('theme-presets', JSON.stringify(updatedPresets));
  } catch (error) {
    console.error('保存用户预设失败:', error);
  }
};

// 获取所有预设（包括默认和用户的）
export const getAllPresets = (): Preset[] => {
  return [...defaultPresets, ...loadUserPresets()];
};